/***************************************************************************
 *   Copyright (C) 2007 by vasaka,,,   *
 *   gorinich.zmey at gmail   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "rng.h"
#include <SDL/SDL.h> 

void RandomizeImage ( int* img_,int width_,int heigth_)
{
	RNG x;  // Not seeded explicitly, so it will be given a random seed.

	for ( int i=0;i<width_*heigth_; i++ ) 
	{
		img_[i]= lround(x.uniform()>0.5? 0:255);
	}
}

//copies first channel to second and third
void CopyChannel ( int* img_,int width_,int heigth_)
{
	for ( int i=0;i<width_*heigth_; i++ ) 
	{
		img_[i]=((img_[i]&0x000000ff)<<0)+((img_[i]&0x000000ff)<<8)+((img_[i]&0x000000ff)<<16);
	}
}

int main(int argc, char *argv[])
{
  if (argc<4) 
  {
    printf("Give me filename and dimensions, please\n");
    printf("Usage:\n");
    printf("%s filename width heigth\n", argv[0]);
    return 0;
  }
  int w = atoi(argv[2]);
  int h = atoi(argv[3]);
  printf("creating %s %dx%d",argv[1], w, h);
  SDL_Surface *screen = SDL_SetVideoMode ( 100,100,32, SDL_SWSURFACE );
  SDL_Surface *pict = SDL_CreateRGBSurface(SDL_SRCCOLORKEY, w, h,32,screen->format->Rmask,screen->format->Gmask,screen->format->Bmask,screen->format->Amask);
  RandomizeImage(( int* )pict->pixels, w,h);
  CopyChannel(( int* )pict->pixels, pict->w,pict->h);
  SDL_SaveBMP(pict,argv[1]);
  return 0;
}
